<?php
class Address_list extends MY_Front_Controller {

	function __construct() {
		parent::__construct();
	}
	
    function index()
    {
        $data = array();

        $this->template->add_js('application/assets/js/address_list.js');
            
       	$this->template->write('pageTitle', lang('adress_list',false));
        $this->template->write_view ( 'content', 'front/address_list.php', $data );
        $this->template->render ();      

    }
    public function save_address()
    {
        $data = array();
        $nume = ($this->input->post('nume'))?$this->input->post('nume'):'';
        $email = ($this->input->post('email'))?$this->input->post('email'):'';
        
        $this->load->model('fe_user_model');
        
        $exists = $this->fe_user_model->get_by_param(array('user_email' => htmlentities($email)));
        
        if (count($exists)){
        	echo json_encode(array('message' => lang('existing_email')));
        	exit(1);
        }
        
        $hasher = new PasswordHash(8, false);
		$this->fe_user_model->fields['user_email'] = htmlentities($email);
		$this->fe_user_model->fields['user_pass'] = $hasher->HashPassword('none');
		$this->fe_user_model->fields['user_date'] = date('Y-m-m h:i:s');
		$this->fe_user_model->fields['first_name'] = htmlentities($nume);
		$this->fe_user_model->fields['language_id'] = $this->config->item('lang_obj')->id;
		$this->fe_user_model->fields['newsletter'] = 1;
		$user = $this->fe_user_model->fields_to_object();
		$user->insert();

    
        echo json_encode(array('message' => lang('email_add_succes')));
    }
}